<?
import("izz.service.TransactionService");
import("iforum.common.Util");
import('iforum.common.IforumRedirect');
import('iforum.common.IforumError');
/**
 *  
 * 
 * @package  iforum.service
 * @author   iCer <iCer@justdn.com>
 * @version  $Id: savereplyService.php,v 1.1 2005/04/06 04:07:55 icer Exp $
 */
class savereplyService extends TransactionService
{

	function execute()
	{
		$context = Singleton::instance('iForumWebAppContext');
		$request = &$context->getRequest();
		$forumid = &$request->getParameter('fid');
		$threadid = &$request->getParameter('tid');

		$currentuser = $context->getCurrentUser();
		$factory = $context->getDaoFactory();
		
		$fdao = $factory->getForumDao();
		$sdao = $factory->getStatusDao();
		$pdao = $factory->getPostDao();
		
		//get forum
		$forum = $fdao->getForum($forumid);

		//add post
		$guid = Guid::newGuid();
		$guid = $guid->toString();		
		
		$post['pGuid'] = $guid;
		$post = &$request->getParameter('post');
		$post['tID'] = $threadid;
		$post['uID'] = $currentuser['uID'];
		$post['pDatetime'] = time();
		$post['uIPAdress'] = &$request->getRemoteAddr();
		
		foreach($post as $key=>$value)
		{
			$post[$key] = htmlencode($value);
		}
		
		$pdao->addPost($post,$forum['fTableID']);
		
		//update forum
		$fdao->updateCount($forum['fID'], 0, 1);
		
		//update global status
		$sdao->updateCount(0,1);
		
		IforumRedirect::go("New reply saved", 
		"index.php?act=thread&amp;fid=".$forumid."&amp;tid=".$threadid);
		return true;
	}
}

?>